import axios from 'axios'
export default {
  namespaced: true,
  state: {
    // token: localStorage.getItem('token') || ''
    token: '',
    userInfo: {}
  },
  mutations: {
    // 保存 token
    updateToken (state, token) {
      state.token = token
      // 持久化存储 token
      // localStorage.setItem('token', token)
    },
    // 保存用户信息
    updateUserInfo (state, userInfo) {
      state.userInfo = userInfo
    }
  },
  actions: {
    async getUserInfo (context) {
      const { data: res } = await axios.get('/my/userinfo')
      if (res.code !== 0) return
      context.commit('updateUserInfo', res.data)
    }
  },
  getters: {}
}
